package com.cnzz.site1255174697.holder;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.cnzz.site1255174697.R;
import com.cnzz.site1255174697.fragment.MallIndexFragment;
import com.cnzz.site1255174697.model.MallListEntity;
import com.cnzz.site1255174697.model.MallTuiEntity;
import com.cnzz.site1255174697.utils.AlibcTradeUtils;
import com.cqyanyu.yanyu.db.XDB;
import com.cqyanyu.yanyu.view.recyclerView.YViewHolder;
import com.facebook.drawee.view.SimpleDraweeView;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.cnzz.site1255174697.fragment.MallIndexFragment.map;

/**
 * 商城列表holder
 */
public class GoodsCellHolder extends YViewHolder<MallTuiEntity.DataBean.ItemsBean.XItemBean> {

    protected SimpleDraweeView imageGoods;
    protected TextView tvGoodsName;
    protected TextView tvPrice;
    protected TextView tvCostPrice;
    protected TextView tvPayNum;
    private String url;

    public GoodsCellHolder(View parent) {
        super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_mall_list, null));
        imageGoods = (SimpleDraweeView) itemView.findViewById(R.id.image_goods);
        tvGoodsName = (TextView) itemView.findViewById(R.id.tv_goodsName);
        tvPrice = (TextView) itemView.findViewById(R.id.tv_price);
        tvCostPrice = (TextView) itemView.findViewById(R.id.tv_cost_price);
        tvPayNum = (TextView) itemView.findViewById(R.id.tv_pay_num);
    }

    @Override
    public void onBindViewHolder(MallTuiEntity.DataBean.ItemsBean.XItemBean itemData) {
        super.onBindViewHolder(itemData);
        imageGoods.setImageURI(itemData.getPic_url());
        tvGoodsName.setText(itemData.getTitle());
        tvPrice.setText(itemData.getPrice());
        tvPayNum.setVisibility(View.GONE);
        url = MallIndexFragment.map.get(itemData.getOpen_id());
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        AlibcTradeUtils.showUrl((Activity) mContext, url);
    }
}
